import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.sql.*;
import java.util.LinkedList;

public class twitter extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		String images = "http://www.stuartsummerfield.com/twitter/images";
		String theCSS = "http://www.stuartsummerfield.com/twitter/styles.css";
		String theJS1 = "http://www.stuartsummerfield.com/twitter/script/jquery.js";
		String theJS2 = "http://www.stuartsummerfield.com/twitter/script/script.js";
		
		// User Signed Out
		String logoutName = request.getParameter("logoutName");
		Object logout = request.getAttribute("logout");
		HttpSession session = request.getSession();
		if (logoutName != null && logout == null) {
			session.invalidate();
			request.setAttribute("logout", "true");
			doGet(request, response);
			return;
		}
		
		
		
		// Get Username from Session
		String user = (String) session.getAttribute("Username");
		
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		Connection conn = null;
		int dbPort = 1521;

		try {
			//slstuart twitter cis fling.seas.upenn.edu
			conn = jdbc.openDBConnection("slstuart", "twitter", "cis", "fling.seas.upenn.edu", dbPort);
			//jdbc.resetDB(conn);
			//System.out.println("reset");
			// Change Tabs depending on whether or not user is logged in
			String messagestab = "";
			String profiletab = "";
			String suggestionstab = "";
			String signintab = "<li><a href=\"#signIn\" class=\"signIn\"><span>Sign in</span></a></li>";
			if (user != null) {
				signintab = "<li><a href='twitter?logoutName=true'><span>Sign out</span></a></li>";
				suggestionstab = "<li><a href=\"#suggestions\">Suggestions</a></li>\n";
				profiletab = "<li><a href=\"#profile\">Profile</a></li>\n";
				messagestab = "<li><a href=\"#messages\">Messages</a></li>\n";
			}
		
			// Initialize Javascript and CSS files
			out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n" +
					"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" +
					"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\" lang=\"fr\"\n" +
					"<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
					"<title>Welcome to Twitter</title>\n" +
					"<link rel=\"stylesheet\" type=\"text/css\" href=\""+theCSS+"\" media=\"screen\" />\n" +
					"<script src=\""+theJS1+"\" type=\"text/javascript\"></script>\n" +
					"<script src=\""+theJS2+"\" type=\"text/javascript\"></script>\n" +
					"</head><body></body>\n");
			
			out.println("<div id=\"frame\"><div id=\"header\">\n" +
					"<a href=\"twitter\"><img src=\""+images+"/Twitter_name_white.png\" id=\"logo\"/></a>\n" +
					"<menu id=\"mainMenu\">\n" +
					"<li><a href=\"#home\" class=\"menuActive home\" >Home</a></li>\n" +
					messagestab +
					profiletab +
					suggestionstab +
					signintab +
					"</menu>\n");

			
			// Sign-In Tab
			// Need to login or create account
			if (user == null) {
				out.println("<div id=\"loginBox\">");
				out.println("<fieldset id=\"loginMenu\" style=\"display:none;\">\n");
				
				out.println("<form action='twitter' method='post'>");
				out.println("Username: <input type='text' name='luser' /><br />");
				out.println("Password: <input type='password' name='lpass' /><br />");
				out.println("<input type='submit' value='Login' />");
				out.println("</form>");
				
				out.println("<form action='twitter' method='post'>");
				out.println("<input type='hidden' name='nuser' value=blah /><br />");
				out.println("<input type='submit' value='Create New Account' />");
				out.println("</form>");
				out.println("</fieldset></div>\n");
			}
			// User is logged in
			else {
				// doPost() to show desired List Page
				String showlist = request.getParameter("showlist");
				if (showlist != null) {
					System.out.println("Show List: " + showlist);
					request.setAttribute("showList", showlist);
					doPost(request, response);
					return;
				}
				// doPost() to show Mentions
				String mentions = request.getParameter("mentions");
				if (mentions != null) {
					System.out.println("Mentions Link Clicked: " + mentions);
					request.setAttribute("mentions", mentions);
					doPost(request, response);
					return;
				}
				// doPost() to show Hashtags
				String hashtag = request.getParameter("hashtag");
				if (hashtag != null) {
					System.out.println("Hashtag Link Clicked: " + hashtag);
					request.setAttribute("hashtag", hashtag);
					doPost(request, response);
					return;
				}
				// ReplyBox
				out.println("</div><div id=\"container\">\n" +
						"<div id=\"replyBox\" style=\"display:none;\">\n" +
						"<form method='post' id='reply' action='twitter'>\n" +
						"<table>\n" +
						"<tr><td><a href=\"#\" class=\"closeReplyBox\">Close<a></td></tr>\n" +
						"<tr><td><textarea class=\"tweetAreaUnFocus replyTextArea\" name='reply' rows=\"3\" style=\"width:300px;position:center;\" onkeyup=\"checkNbCharacter(null,this);\"  onkeypress=\"return checkNbCharacter(event, this, 'replyTweetLeftCharacters');\"></textarea></tr></td>\n" +
						"<tr><td>\n" +
						"<input type='submit' value='Send' />\n" +
						"<span  id=\"replyTweetLeftCharacters\">142</span></tr></td>\n" +
						"</table></form>\n");
				out.println("</div>\n");
				
				// Home Tab
				// Right Side --> Followers
				
				out.println("<div id=\"home\" class=\"content\">\n" +
						"<div id=\"rightSide\">\n");
				out.println("<div class=\"followers\">People You're Following :</div>\n");
				// People your following
				
				// Unfollow
				String unfollow = request.getParameter("unfollow");
				Object unfollow2 = request.getAttribute("unfollow");
				if (unfollow != null && unfollow2 == null) {
					try {
						jdbc.remFollow(conn, unfollow, user);
						out.println("<P>Successfully UnFollowed User " + unfollow + "!</P>");
					}
					catch (SQLException e) {
						e.printStackTrace();
						out.println("<P>Error, UnFollowing User Failed!</P>");
					}
					request.setAttribute("unfollow", "true");
					doGet(request, response);
					return;
				}
				
				out.println("<div id=\"listTweets\" >\n");
				try {
					LinkedList<String> followees = jdbc.getFollowees(conn, user);
					for (int i = 0; i < followees.size(); i++) {
						String unfString = "twitter?unfollow=" + followees.get(i);
						out.println("<div class='tweet'>\n");
						out.println("<span class='author'>" + followees.get(i) + "</span>\n");
						out.println("<div class='options'>\n");
						out.println("<a href=" + unfString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>Unfollow</a>\n");
						out.println("</div>\n");
						out.println("</div>\n");
					}	
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting Followees failed!</P>");
				}
				out.println("</div>\n");
				
				
				out.println("<div class=\"followers\">People Following You :</div>\n");
				// people following you
				try {
					LinkedList<String> followers = jdbc.getFollowers(conn, user);
					for (int i = 0; i < followers.size(); i++) {
						out.println("<span class=\"userName\">" + followers.get(i)+ "</span><br/>\n");
					}
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting followees Failed!</P>");
				}
				
				// Search
				out.println("<form action='twitter' method='post'>\n" +
						"<input id=\"search\" name='searchterm' value=\"search\" id=\"search\" class=\"searchUnFocus\"/>\n" +
						"<input type='submit' value='Search' />\n" +
						"</form>\n");
				
				// Create New List
				out.println("<form action='twitter' method='post'>");
				out.println("<input type='hidden' name='nlist' value=blah /><br />");
				out.println("<input type='submit' value='Create New List' />");
				out.println("</form>");
				
				// Show Lists You've Created
				out.println("<div class=\"followers\">Lists You've Created :</div>\n");
				try {
					LinkedList<String> createdLists = jdbc.getUserLists(conn, user);
					for (int i = 0; i < createdLists.size(); i++) {
						String theListName = createdLists.get(i);
						String urlLink = "<a href=\"twitter?showlist=" + theListName + "\">" + theListName + "</a>";
						out.println("<span class=\"userName\">" + urlLink+ "</span><br/>\n");
					}
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting User Created Lists Failed!</P>");
				}
				
				// Show Lists You're Following
				out.println("<div class=\"followers\">Lists You're Following :</div>\n");
				try {
					LinkedList<String> createdLists = jdbc.getAllFollowedLists(conn, user);
					for (int i = 0; i < createdLists.size(); i++) {
						String theListName = createdLists.get(i);
						String urlLink = "<a href=\"twitter?showlist=" + theListName + "\">" + theListName + "</a>";
						out.println("<span class=\"userName\">" + urlLink+ "</span><br/>\n");
					}
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting User Created Lists Failed!</P>");
				}
				
				// Show Favorite Tweets
				out.println("<form action='twitter' method='post'>");
				out.println("<input type='hidden' name='showFavorites' value=blah /><br />");
				out.println("<input type='submit' value='Show Favorite Tweets' />");
				out.println("</form>");
				
				out.println("</div>\n");

				
				
				// Left Side --> Tweets
				// Make new Tweet
				out.println("<div id=\"leftSide\">\n" +
						"<p><h1>What's up " + user + "?</h1>\n" +
						"<span class=\"tweetZone\">\n" +
						"<form method='post' action='twitter'>\n" +
						"<textarea class=\"tweetAreaUnFocus tweetRedaction\" name='newtweet' rows=\"3\" cols=\"40\"></textarea>\n" +
						"<br />\n" +
						"<input style='' type='submit' value='Tweet It!' /><span style=\"margin-left:10px;\" id=\"mainTweetLeftCharacters\">142</span>\n" +
						"</form>" +
						"</span></p><p>\n");
				
				out.println("<a href=\"#\" id=\"tabTweets\" class=\"tabSelected\">Last Tweets</a>\n");
				
				// Show All Tweets
				
				// Favorite a Tweet
				String fav = request.getParameter("fav");
				Object fav2 = request.getAttribute("fav");
				if (fav != null && fav2 == null) {
					try {
						int msgID = Integer.parseInt(fav);
						System.out.println("Tweet Favorited: " + msgID);
						jdbc.addFavorite(conn, user, msgID);
					}
					catch (SQLException e) {
						e.printStackTrace();
						out.println("<P>Error, Favoriting Tweet Failed!</P>");
					}
					request.setAttribute("fav", "true");
					doGet(request, response);
					return;
				}
				
				// Remove Favorite
				String rfav = request.getParameter("rfav");
				Object rfav2 = request.getAttribute("rfav");
				if (rfav != null && rfav2 == null) {
					try {
						int msgID = Integer.parseInt(rfav);
						System.out.println("Tweet Favorite Remove: " + msgID);
						jdbc.remFavorite(conn, user, msgID);
					}
					catch (SQLException e) {
						e.printStackTrace();
						out.println("<P>Error, Removing Favorite Tweet Failed!</P>");
					}
					request.setAttribute("rfav", "true");
					doGet(request, response);
					return;
				}
				
				// Retweet
				String retweet = request.getParameter("retweet");
				Object retweet2 = request.getAttribute("retweet");
				if (retweet != null && retweet2 == null) {
					try {
						System.out.println("Retweet: " + retweet);
						// getMsgString(msgID)
						String content = jdbc.getMsgString(conn, Integer.parseInt(retweet));
						jdbc.newTweet(conn, user, content);
					}
					catch (SQLException e) {
						e.printStackTrace();
						out.println("<P>Error, Retweeting Failed!</P>");
					}
					request.setAttribute("retweet", "true");
					doGet(request, response);
					return;
				}
				
				// Delete Tweet
				String deltweet = request.getParameter("deltweet");
				Object deltweet2 = request.getAttribute("deltweet");
				if (deltweet != null && deltweet2 == null) {
					try {
						System.out.println("Delete Tweeet: " + deltweet);
						jdbc.remTweet(conn, Integer.parseInt(deltweet));
					}
					catch (SQLException e) {
						e.printStackTrace();
						out.println("<P>Error, Deleting Tweet Failed!</P>");
					}
					request.setAttribute("deltweet", "true");
					doGet(request, response);
					return;
				}
				
				out.println("<div id=\"listTweets\" >\n");
				try {
					LinkedList<LinkedList<String>> getAllTweets = jdbc.getAllTweets(conn, user);
					LinkedList<String> authors = getAllTweets.get(0);
					LinkedList<String> tweets = getAllTweets.get(1);
					LinkedList<String> dates = getAllTweets.get(2);
					LinkedList<String> msgIds = getAllTweets.get(3);
					for (int i = 0; i < authors.size(); i++) {
						String favString = "twitter?fav=" + msgIds.get(i);
						String retweetString = "twitter?retweet=" + msgIds.get(i);
						String deltweetString = "twitter?deltweet=" + msgIds.get(i);
						out.println("<div class='tweet'>\n");
						out.println("<span class='author'>" + authors.get(i) + "</span>\n");
						out.println("<span class='name'>" + dates.get(i) + "</span><br />\n");
						out.println("<span class='text'>");
						
						String tweetContent = tweets.get(i);
						char[] thetweet = tweetContent.toCharArray();
						for (int l = 0; l < thetweet.length; l++) {
							char cur = thetweet[l];
							if (cur == '@') {
								StringBuffer themen = new StringBuffer();
								for (int g = l+1; g < thetweet.length; g++) {
									char cur2 = thetweet[g];
									if (cur2 == ' ') {
										out.print("<a href=\"twitter?mentions=" + themen.toString() + "\">@" + 
												themen.toString() + "</a>");
										l = g - 1;
										break;
									}
									themen.append(cur2);
								}
							}
							else if (cur == '#') {
								StringBuffer thetag = new StringBuffer();
								for (int g = l+1; g < thetweet.length; g++) {
									char cur2 = thetweet[g];
									if (cur2 == ' ') {
										out.print("<a href=\"twitter?hashtag=" + thetag.toString() + "\">#" + 
												thetag.toString() + "</a>");
										l = g - 1;
										break;
									}
									thetag.append(cur2);
								}
							}
							else
								out.print(cur);
						}
						
						out.println("</span>\n");
						out.println("<div class='options'>\n");
						out.println("<a href="+ favString +" class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/favorite.png\" />favorite</a>\n");
						out.println("<a href=" + retweetString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>retweet</a>\n");
						out.println("<a href=\"#\" class=\"link linkReplyBox\"><img class=\"optionsIcon\" src=\""+images+"/reply.png\" />reply</a>\n");
						if (user.equals(authors.get(i)))
							out.println("<a href=" + deltweetString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>DELETE</a>\n");
						out.println("</div>\n");
						out.println("</div>\n");
					}	
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting Tweets Failed!</P>");
				}
				out.println("</div>\n");
				
				
				out.println("</p></div></div>\n");
				
				// Messages Tab
				// New Private Message
				out.println("<div id=\"messages\" class=\"content\" style=\"display:none;\">\n");
				out.println("<h1>Write A Private Message</h1>\n");
				
				out.println(
							"<table class=\"table-register\">\n" +
							"<form action='twitter' method='post'>\n" +
							"<tr>\n" +
							"<td class=\"label-input-register\">* To:</td>\n" +
							"<td class=\"value-input-register\"><input type=\"text\" class=\"inputUnFocus\" name='pMsgName' title=\"firstName\" /></td>\n" +
							"<td class=\"js-input-register\" >A Recipient is required.</td>\n" +
							"</tr>\n" +
							"<tr>\n" +
							"<td class=\"label-input-register\">Message:</td>\n" +
							"<td class=\"value-input-register\"><textarea class=\"tweetAreaUnFocus\" name='pMsgContent' title=\"bio\" cols=\"100\" maxlength=\"142\" size=\"142\"></textarea></td>\n" +
							"<td class=\"js-input-register\" >142</td>\n" +
							"</tr>\n" +
							"<tr>\n" +
							"<td colspan=\"2\" >\n" +
							"<input type=\"submit\" value='Send Message' />\n" +
							"<input type=\"reset\" value='Reset' />\n" +
							"</td>\n" +
							"</tr>\n" +
							"</form>\n" +
							"</table>\n"
							);
				
				// Delete Private Message
				String delmsg = request.getParameter("delmsg");
				Object delmsg2 = request.getAttribute("delmsg");
				if (delmsg != null && delmsg2 == null) {
					try {
						System.out.println("Delete Message: " + delmsg);
						jdbc.remMsg(conn, Integer.parseInt(delmsg));
					}
					catch (SQLException e) {
						e.printStackTrace();
						out.println("<P>Error, Deleting Private Message Failed!</P>");
					}
					request.setAttribute("delmsg", "true");
					doGet(request, response);
					return;
				}
				
				// List Private Messages
				out.println("<div id=\"listTweets\" >\n");
				try {
					LinkedList<LinkedList<String>> getAllTweets = jdbc.getPrivateMessages(conn, user);
					LinkedList<String> authors = getAllTweets.get(0);
					LinkedList<String> tweets = getAllTweets.get(1);
					LinkedList<String> dates = getAllTweets.get(2);
					LinkedList<String> msgIds = getAllTweets.get(3);
					LinkedList<String> recipients = getAllTweets.get(4);
					for (int i = 0; i < authors.size(); i++) {
						//String favString = "twitter?fav=" + msgIds.get(i);
						//String retweetString = "twitter?retweet=" + msgIds.get(i);
						String peeps = "From: " + authors.get(i) + " --> " + recipients.get(i);
						String delmsgString = "twitter?delmsg=" + msgIds.get(i);
						out.println("<div class='tweet'>\n");
						out.println("<span class='author'>" + peeps + "</span>\n");
						out.println("<span class='name'>" + dates.get(i) + "</span><br />\n");
						out.println("<span class='text'>");
						
						String tweetContent = tweets.get(i);
						char[] thetweet = tweetContent.toCharArray();
						for (int l = 0; l < thetweet.length; l++) {
							char cur = thetweet[l];
							if (cur == '@') {
								StringBuffer themen = new StringBuffer();
								for (int g = l+1; g < thetweet.length; g++) {
									char cur2 = thetweet[g];
									if (cur2 == ' ') {
										out.print("<a href=\"twitter?mentions=" + themen.toString() + "\">@" + 
												themen.toString() + "</a>");
										l = g - 1;
										break;
									}
									themen.append(cur2);
								}
							}
							else if (cur == '#') {
								StringBuffer thetag = new StringBuffer();
								for (int g = l+1; g < thetweet.length; g++) {
									char cur2 = thetweet[g];
									if (cur2 == ' ') {
										out.print("<a href=\"twitter?hashtag=" + thetag.toString() + "\">#" + 
												thetag.toString() + "</a>");
										l = g - 1;
										break;
									}
									thetag.append(cur2);
								}
							}
							else
								out.print(cur);
						}
						
						out.println("</span>\n");
						out.println("<div class='options'>\n");
						//out.println("<a href="+ favString +" class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/favorite.png\" />favorite</a>\n");
						//out.println("<a href=" + retweetString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>retweet</a>\n");
						//out.println("<a href=\"#\" class=\"link linkReplyBox\"><img class=\"optionsIcon\" src=\""+images+"/reply.png\" />reply</a>\n");
						if (user.equals(authors.get(i)))
							out.println("<a href=" + delmsgString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>DELETE</a>\n");
						out.println("</div>\n");
						out.println("</div>\n");
					}	
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting Private Messages Failed!</P>");
				}
				out.println("</div>\n");
				
				out.println("</div>\n");
				
				// Profile Tab
				ResultSet theUser = null;
				try {
					theUser = jdbc.getUser(conn, user);
				}
				catch (SQLException e) {
					theUser = null;
				}
				
				String priv = theUser.getString("privacyPolicy");
				if (priv.equals("Y"))
					priv = "Protected";
				else
					priv = "Public";
				
				out.println("<div id=\"profile\" class=\"content\" style=\"display:none;\">" +
						"<div id=\"rightSide\">\n" +
						"<span style=\"font-weight: bold;font-size:1.2em;\">Waiting List<span>\n");
				
				out.println("<div class=\"followers\">Privacy: " + priv + "</div>\n");
				out.println("<div id=\"waintingList\">\n");
				
				// Waiting to Follow if Private
//				if (priv.equals("Y")) {
					// Waiting List on Right Side
					try {
						LinkedList<String> waitingToFollow = jdbc.getWaitingToFollow(conn, user);
						// Process Waiting To Follow Accept/Deny
						Object decis = request.getAttribute("wtf");
						for (int i = 0; i < waitingToFollow.size(); i++) {
							String decision = request.getParameter("wtf" + waitingToFollow.get(i));
							if (decision != null && decis == null) {
								if (decision.equals("Deny")) {
									System.out.println(waitingToFollow.get(i) + " Denied!");
									jdbc.remWTF(conn, waitingToFollow.get(i), user);
								}
								else {
									System.out.println(waitingToFollow.get(i) + " Accepted!");
									String wtf = waitingToFollow.get(i);
									jdbc.newFollowAccepted(conn, wtf, user);
									jdbc.remWTF(conn, wtf, user);
								}
								request.setAttribute("wtf", "true");
								doGet(request, response);
								return;
							}
						}
						
						for (int i = 0; i < waitingToFollow.size(); i++) {
							String wtfYes = "twitter?wtf" + waitingToFollow.get(i) + "=Accept";
							String wtfNo = "twitter?wtf" + waitingToFollow.get(i) + "=Deny";
							out.println("<div class=\"waitingElement\">\n");
							out.println("<span class=\"waitingName\">" + waitingToFollow.get(i) + "</span>\n");
							out.println("<span class=\"decisionIcons\" ><a href=" + wtfYes + " ><img class=\"decisionButton\" src=\""+images+"/validate.png\" alt=\"Accept\" style=\"margin-right:10px;\"/></a>\n");
							out.println("<a href=" + wtfNo + "><img class=\"decisionButton\" src=\""+images+"/cancel.png\" alt=\"Refuse\"/></a></span>\n");
							out.println("</div>\n");
						}
					}
					catch (SQLException e) {
						e.printStackTrace();
						out.println("<P>Error, Getting Waiting To Follow Failed!</P>");
					}
//				}
//				else {
//					out.println("<p>Your Privacy: Public</p>\n");
//				}
				out.println("</div></div>\n");
				
				
				String fName = theUser.getString("firstName");
				String lName = theUser.getString("lastName");
				String location = theUser.getString("location");
				String webpage = theUser.getString("webpage");
				
				
				// Edit Profile on Left Side
				out.println("<div id=\"leftSide\">\n" +
						"<h3>Edit your profile " + user + "</h3>\n" +
						"<form id=\"form-register\" action='twitter' method='post'>\n" +
						"<table class=\"table-register\">\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">* Password:</td>\n" +
						"<td class=\"value-input-register\"><input type=\"password\" class=\"inputUnFocus\" name=\"password\" value=\"\" title=\"password\" id=\"password-value\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-password-value\">A password is required.</td>\n" +
						"</tr><tr>\n" +
						"<td class=\"label-input-register\"><label for=\"repassword\">* Re-type Password:</label></td>\n" +
						"<td class=\"value-input-register\"><input type=\"password\" class=\"inputUnFocus\" name=\"repassword\" value=\"\" title=\"password\" id=\"repassword-value\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-repassword-value\">The passwords don't match.</td>\n" +
						"</tr><tr>\n" +
						"<td class=\"label-input-register\">* First name:</td>\n" +
						"<td class=\"value-input-register\"><input type=\"text\" class=\"inputUnFocus\" name=\"firstName\" value='"+ fName +"' title=\"firstName\" id=\"firstName-value\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-firstName-value\">Your first name is required.</td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">* Last name:</td>\n" +
						"<td class=\"value-input-register\"><input type=\"text\" class=\"inputUnFocus\" name=\"lastName\" value='"+ lName +"' title=\"lastName\" id=\"lastName-value\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-lastName-value\">Your last name is required.</td>\n" +
						"</tr>" +
						"<tr>\n" +
						"<td class=\"label-input-register\">Privacy level:</td>\n" +
						"<td class=\"value-input-register\">\n" +
						"<select name=\"privacy\" id=\"privacy-value\">\n" +
						"<option selected=\"selected\">Public</option>\n" +
						"<option>Protected</option>\n" +
						"</select>\n" +
						"</td>\n" +
						"<td class=\"js-input-register\" id=\"js-privacy-value\"></td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">Bio:</td>\n" +
						"<td class=\"value-input-register\"><textarea class=\"tweetAreaUnFocus\" name=\"bio\" title=\"bio\" id=\"bio-value\" cols=\"100\" maxlength=\"142\" size=\"142\"></textarea></td>\n" +
						"<td class=\"js-input-register\" id=\"js-bio-value\">142</td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">Webpage:</td>\n" +
						"<td class=\"value-input-register\"><input type=\"text\" class=\"inputUnFocus\" name=\"webpage\" value='"+ webpage +"' id=\"webpage-value\" title=\"webpage\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-webpage-value\"></td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">Location:</td>\n" +
						"<td class=\"value-input-register\"><input type=\"text\" class=\"inputUnFocus\" name=\"location\" value='"+ location +"' id=\"location-value\" title=\"location\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-location-value\"></td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">Timezone:</td>\n");
				
				out.println("<td class=\"value-input-register\">\n" +
						"<select name=\"timezone\" id=\"timezone-value\">\n" +
						"<option selected=\"selected\">None</option>\n" +
						"<option>UTC-12</option>\n" +
						"<option>UTC-11</option>\n" +
						"<option>UTC-10</option>\n" +
						"<option>UTC-09</option>\n" +
						"<option>UTC-08</option>\n" +
						"<option>UTC-07</option>\n" +
						"<option>UTC-06</option>\n" +
						"<option>UTC-05</option>\n" +
						"<option>UTC-04</option>\n" +
						"<option>UTC-03</option>\n" +
						"<option>UTC-02</option>\n" +
						"<option>UTC-01</option>\n" +
						"<option>UTC</option>\n" +
						"<option>UTC+01</option>\n" +
						"<option>UTC+02</option>\n" +
						"<option>UTC+03</option>\n" +
						"<option>UTC+04</option>\n" +
						"<option>UTC+05</option>\n" +
						"<option>UTC+06</option>\n" +
						"<option>UTC+07</option>\n" +
						"<option>UTC+08</option>\n" +
						"<option>UTC+09</option>\n" +
						"<option>UTC+10</option>\n" +
						"<option>UTC+11</option>\n" +
						"<option>UTC+12</option>\n" +
						"<option>UTC+13</option>\n" +
						"<option>UTC+14</option>\n" +
						"</select>\n" +
						"</td>\n" +
						"<td class=\"js-input-register\" id=\"js-timezone-value\"></td>\n" +
						"</tr>\n");
				
				out.println("<tr>\n" +
						"<td class=\"label-input-register\">Language:</td>\n" +
						"<td class=\"value-input-register\">\n" +
						"<select id=\"language-value\" name=\"language\">\n" +
						"<option selected=\"selected\">English</option>\n" +
						"<option>French</option>\n" +
						"<option>German</option>\n" +
						"<option>Spanish</option>\n" +
						"</select>\n" +
						"</td>\n" +
						"<td class=\"js-input-register\" id=\"js-language-value\"></td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td id=\"required_text\" class=\"label-input-register\">* Required</td>\n" +
						"<td class=\"value-input-register\" />\n" +
						"<td class=\"js-input-register\" id=\"js-required-value\"></td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td colspan=\"2\" id=\"buttons-register\">\n" +
						"<input type=\"submit\" />\n" +
						"<input type=\"reset\" />\n" +
						"</td>\n" +
						"<td/>\n" +
						"</tr>\n" +
						"</table>\n" +
						"</form>\n" +
						"</div>\n" +
						"</div>\n");
				
				// Suggestions Tab
				out.println("<div id=\"suggestions\" class=\"content\" style=\"display:none;\">\n" +
						"<h3>Suggestions</h3>\n");
				out.println("<div id=\"listTweets\" >\n");
				
				try {
					// getSuggestions
					LinkedList<String> suggUsers = jdbc.getWhoToFolSuggestions(conn, user);
					
					for (int k = 0; k < suggUsers.size(); k++) {
						out.println("<div class=\"tweet\">\n");
						out.println("<span class=\"author\">" + suggUsers.get(k) + "</span>\n");
						out.println("<form action='twitter' method='post'>");
						out.println("<input type='hidden' name='foluser' value=" + suggUsers.get(k) + " /><br />");
						out.println("<input type='submit' value='Follow This User' />");
						out.println("</form>");
						out.println("</div>\n");
					}
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Get Who To Follow Suggestions Failed!</P>");
				}
				
				out.println("</div></div>\n");
				
				// Reset The Database, For Debugging
				out.println("<form action='twitter' method='post'>");
				out.println("<input type='hidden' name='resetDB' value=blah />");
				out.println("<input type='submit' value='Reset the Database' />");
				out.println("</form>");
				
				out.println("</div></body>\n" +
						"</html>\n" );
			}
		
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		finally {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

	}
	
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		String images = "http://www.stuartsummerfield.com/twitter/images";
		String theCSS = "http://www.stuartsummerfield.com/twitter/styles.css";
		String theJS1 = "http://www.stuartsummerfield.com/twitter/script/jquery.js";
		String theJS2 = "http://www.stuartsummerfield.com/twitter/script/script.js";
		
		HttpSession session = request.getSession();
		String user = (String) session.getAttribute("Username");
		
		String luser = request.getParameter("luser");
		String lpass = request.getParameter("lpass");
		String nuser = request.getParameter("nuser");
		String resetDB = request.getParameter("resetDB");
		
		// New Account params
		String pseudo = request.getParameter("pseudo");
		String password = request.getParameter("password");
		String firstName = request.getParameter("firstName");
		String lastName = request.getParameter("lastName");
		String email = request.getParameter("email");
		String privacy = request.getParameter("privacy");
		String bio = request.getParameter("bio");
		String webpage = request.getParameter("webpage");
		String timezone = request.getParameter("timezone");
		String language = request.getParameter("language");
		String location = request.getParameter("location");
		
		// Buttons from Show List Page
		String delList = request.getParameter("delList");
		String editList = request.getParameter("editList");
		String addListUser = request.getParameter("addListUser");
		String addListFollow = request.getParameter("addListFollow");
		String remListFollow = request.getParameter("remListFollow");
		String delListUser = request.getParameter("delListUser");
		String delListUserL = request.getParameter("delListUserL");
		String allowListUser = request.getParameter("allowListUser");
		String allowListUserL = request.getParameter("allowListUserL");
		String allowListMember = request.getParameter("allowListMember");
		String allowListMemberL = request.getParameter("allowListMemberL");
		String addListUserName = request.getParameter("addListUserName");
		String addListUserLName = request.getParameter("addListUserLName");
		String editListName = request.getParameter("editListName");
		String editListDesc = request.getParameter("editListDesc");
		String editListPrivacy = request.getParameter("editListPrivacy");
		
		// More Params
		String reply = request.getParameter("reply");
		String newtweet = request.getParameter("newtweet");
		String nlist = request.getParameter("nlist");
		String foluser = request.getParameter("foluser");
		String listName = request.getParameter("listName");
		String listDesc = request.getParameter("listDesc");
		String listPrivacy = request.getParameter("listPrivacy");
		String showFavorites = request.getParameter("showFavorites");
		String pMsgName = request.getParameter("pMsgName");
		String pMsgContent = request.getParameter("pMsgContent");
		String listUsers = request.getParameter("listUsers");
		Object showList2 = request.getAttribute("showList");
		String showList = null;
		if (showList2 != null)
			showList = showList2.toString();
		Object mentions2 = request.getAttribute("mentions");
		String mentions = null;
		if (mentions2 != null)
			mentions = mentions2.toString();
		Object hashtag2 = request.getAttribute("hashtag");
		String hashtag = null;
		if (hashtag2 != null)
			hashtag = hashtag2.toString();
		String searchterm = request.getParameter("searchterm");
		
		if (privacy != null && privacy.equals("Public"))
			privacy = "N";
		if (privacy != null && privacy.equals("Protected"))
			privacy = "Y";
		
		out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n" +
				"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" +
				"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\" lang=\"fr\"\n" +
				"<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
				"<title>Welcome to Twitter</title>\n" +
				"<link rel=\"stylesheet\" type=\"text/css\" href=\""+theCSS+"\" media=\"screen\" />\n" +
				"<script src=\""+theJS1+"\" type=\"text/javascript\"></script>\n" +
				"<script src=\""+theJS2+"\" type=\"text/javascript\"></script>\n" +
				"</head><body></body>\n");
		
		out.println("<div id=\"frame\"><div id=\"header\">\n" +
				"<a href=\"twitter\"><img src=\""+images+"/Twitter_name_white.png\" id=\"logo\"/></a>\n" +
				"<menu id=\"mainMenu\">\n" +
				"<li><a href=\"twitter\" class=\"home changePage\" >Home</a></li>\n" +
				"</menu>\n" +
				"</div>\n");

		out.println("<div id=\"container\">\n");
		
		Connection conn = null;
		int dbPort = 1521;

		try {
			//slstuart twitter cis fling.seas.upenn.edu
			conn = jdbc.openDBConnection("slstuart", "twitter", "cis", "fling.seas.upenn.edu", dbPort);
			
			// Reset Database for Debugging
			if (resetDB != null) {
				jdbc.resetDB(conn);
				out.println("<P>The Database is Reset!</P>");
			}
			
			// Search
			if (searchterm != null) {
				out.println("<P>Your Search-Term: " + searchterm + "</P>");
				// Users?
				out.println("<div class=\"followers\">Relevant Users:</div>\n");
				try {
					LinkedList<String> createdLists = jdbc.getSearchUsers(conn, searchterm);
					for (int i = 0; i < createdLists.size(); i++) {
						String theListName = createdLists.get(i);
						out.println("<div class=\"tweet\">\n");
						out.println("<span class=\"author\">" + theListName + "</span>\n");
						out.println("<form action='twitter' method='post'>");
						out.println("<input type='hidden' name='foluser' value=" + theListName + " /><br />");
						out.println("<input type='submit' value='Follow This User' />");
						out.println("</form>");
						out.println("</div>\n");
					}
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting Search Lists Failed!</P>");
				}
				// Lists?
				out.println("<div class=\"followers\">Relevant Lists:</div>\n");
				try {
					LinkedList<String> createdLists = jdbc.getSearchLists(conn, searchterm);
					for (int i = 0; i < createdLists.size(); i++) {
						String theListName = createdLists.get(i);
						String urlLink = "<a href=\"twitter?showlist=" + theListName + "\">" + theListName + "</a>";
						out.println("<span class=\"userName\">" + urlLink+ "</span><br/>\n");
					}
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting Search Lists Failed!</P>");
				}
				//HashTags?
				out.println("<div class=\"followers\">Hashtag Tweets:</div>\n");
				out.println("<div id=\"listTweets\" >\n");
				try {
					LinkedList<LinkedList<String>> getAllTweets = jdbc.getHashtags(conn, user, searchterm);
					LinkedList<String> authors = getAllTweets.get(0);
					LinkedList<String> tweets = getAllTweets.get(1);
					LinkedList<String> dates = getAllTweets.get(2);
					LinkedList<String> msgIds = getAllTweets.get(3);
					for (int i = 0; i < authors.size(); i++) {
						String favString = "twitter?fav=" + msgIds.get(i);
						String retweetString = "twitter?retweet=" + msgIds.get(i);
						String deltweetString = "twitter?deltweet=" + msgIds.get(i);
						out.println("<div class='tweet'>\n");
						out.println("<span class='author'>" + authors.get(i) + "</span>\n");
						out.println("<span class='name'>" + dates.get(i) + "</span><br />\n");
						out.println("<span class='text'>");
						
						String tweetContent = tweets.get(i);
						char[] thetweet = tweetContent.toCharArray();
						for (int l = 0; l < thetweet.length; l++) {
							char cur = thetweet[l];
							if (cur == '@') {
								StringBuffer themen = new StringBuffer();
								for (int g = l+1; g < thetweet.length; g++) {
									char cur2 = thetweet[g];
									if (cur2 == ' ') {
										out.print("<a href=\"twitter?mentions=" + themen.toString() + "\">@" + 
												themen.toString() + "</a>");
										l = g - 1;
										break;
									}
									themen.append(cur2);
								}
							}
							else if (cur == '#') {
								StringBuffer thetag = new StringBuffer();
								for (int g = l+1; g < thetweet.length; g++) {
									char cur2 = thetweet[g];
									if (cur2 == ' ') {
										out.print("<a href=\"twitter?hashtag=" + thetag.toString() + "\">#" + 
												thetag.toString() + "</a>");
										l = g - 1;
										break;
									}
									thetag.append(cur2);
								}
							}
							else
								out.print(cur);
						}
						
						out.println("</span>\n");
						out.println("<div class='options'>\n");
						out.println("<a href="+ favString +" class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/favorite.png\" />favorite</a>\n");
						out.println("<a href=" + retweetString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>retweet</a>\n");
						out.println("<a href=\"#\" class=\"link linkReplyBox\"><img class=\"optionsIcon\" src=\""+images+"/reply.png\" />reply</a>\n");
						if (user.equals(authors.get(i)))
							out.println("<a href=" + deltweetString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>DELETE</a>\n");
						out.println("</div>\n");
						out.println("</div>\n");
					}	
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting Tweets Failed!</P>");
				}
				out.println("</div>\n");
				
				//Mentions?
				out.println("<div class=\"followers\">Mentions Tweets:</div>\n");
				out.println("<div id=\"listTweets\" >\n");
				try {
					LinkedList<LinkedList<String>> getAllTweets = jdbc.getMentions(conn, user, searchterm);
					LinkedList<String> authors = getAllTweets.get(0);
					LinkedList<String> tweets = getAllTweets.get(1);
					LinkedList<String> dates = getAllTweets.get(2);
					LinkedList<String> msgIds = getAllTweets.get(3);
					for (int i = 0; i < authors.size(); i++) {
						String favString = "twitter?fav=" + msgIds.get(i);
						String retweetString = "twitter?retweet=" + msgIds.get(i);
						String deltweetString = "twitter?deltweet=" + msgIds.get(i);
						out.println("<div class='tweet'>\n");
						out.println("<span class='author'>" + authors.get(i) + "</span>\n");
						out.println("<span class='name'>" + dates.get(i) + "</span><br />\n");
						out.println("<span class='text'>");
						
						String tweetContent = tweets.get(i);
						char[] thetweet = tweetContent.toCharArray();
						for (int l = 0; l < thetweet.length; l++) {
							char cur = thetweet[l];
							if (cur == '@') {
								StringBuffer themen = new StringBuffer();
								for (int g = l+1; g < thetweet.length; g++) {
									char cur2 = thetweet[g];
									if (cur2 == ' ') {
										out.print("<a href=\"twitter?mentions=" + themen.toString() + "\">@" + 
												themen.toString() + "</a>");
										l = g - 1;
										break;
									}
									themen.append(cur2);
								}
							}
							else if (cur == '#') {
								StringBuffer thetag = new StringBuffer();
								for (int g = l+1; g < thetweet.length; g++) {
									char cur2 = thetweet[g];
									if (cur2 == ' ') {
										out.print("<a href=\"twitter?hashtag=" + thetag.toString() + "\">#" + 
												thetag.toString() + "</a>");
										l = g - 1;
										break;
									}
									thetag.append(cur2);
								}
							}
							else
								out.print(cur);
						}
						
						out.println("</span>\n");
						out.println("<div class='options'>\n");
						out.println("<a href="+ favString +" class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/favorite.png\" />favorite</a>\n");
						out.println("<a href=" + retweetString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>retweet</a>\n");
						out.println("<a href=\"#\" class=\"link linkReplyBox\"><img class=\"optionsIcon\" src=\""+images+"/reply.png\" />reply</a>\n");
						if (user.equals(authors.get(i)))
							out.println("<a href=" + deltweetString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>DELETE</a>\n");
						out.println("</div>\n");
						out.println("</div>\n");
					}	
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting Tweets Failed!</P>");
				}
				out.println("</div>\n");
			}
			
			// Reply NewTweet
			if (reply != null) {
				System.out.println("Reply Was: " + reply);
				try {
					jdbc.newTweet(conn, user, reply);
					out.println("<P>Successfully Replied!</P>");
					doGet(request, response);
					return;
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Reply Failed!</P>");
				}
			}
			
			// New Private Message
			if (pMsgName != null) {
				ResultSet theUser = null;
				try {
					theUser = jdbc.getUser(conn, pMsgName);
				}
				catch (SQLException e) {
					theUser = null;
				}
				if (theUser == null) {
					out.println("<P>Uh Oh, Recipient Name Does Not Exist!</P>");
				}
				else {
					try {
						jdbc.newMsg(conn, user, pMsgContent, pMsgName);
						out.println("<P>You Sent a Private Message to " + pMsgName + "!</P>");
					}
					catch (SQLException e) {
						e.printStackTrace();
						out.println("<P>Error, New Private Message Failed!</P>");
					}
				}
				
			}
			
			// NewTweet
			if (newtweet != null) {
				System.out.println("NewTweet was: " + newtweet + " From user: " + user);
				try {
					jdbc.newTweet(conn, user, newtweet);
					out.println("<P>Successfully Tweeted!</P>");
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Tweet Failed!</P>");
				}
			}
			
			// FolUser
			if (foluser != null) {
				System.out.println("UserToFollow was: " + foluser);
				try {
					jdbc.newFollow(conn, user, foluser);
					out.println("<P>Successfully Followed User " + foluser + "!</P>");
					doGet(request, response);
					return;
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Following User Failed!</P>");
				}
			}
			
			// Delete List
			if (delList != null) {
				System.out.println("ListToDelete was: " + delList);
				try {
					int lid = Integer.parseInt(delList);
					jdbc.remList(conn, lid);
					out.println("<P>Successfully Deleted List!</P>");
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Deleting List Failed!</P>");
				}
			}
			
			// Edit List page
			if (editList != null) {
				System.out.println("ListToEdit was: " + editList);
				out.println("<P>Editing List</P>");
				out.println("<div id=\"listBox\" >\n" +  
						"<form method=\"post\" action=\"twitter\">\n" +
						"<table>\n" +
						"<tr><td style=\"width:90px;text-align:right;\">Description :</td><td><textarea maxlength=\"142\" class=\"tweetAreaUnFocus descriptionList\" name='editListDesc' rows=\"3\" style=\"width:300px;position:center;\" ></textarea></td></tr>\n" +
						"<tr><td style=\"width:90px;text-align:right;\">Privacy :</td><td>\n" +
						"<select style=\"width:300px;\" name=\"editListPrivacy\" id=\"privacy-value\">\n" +
						"<option selected=\"selected\">Public</option>\n" +
						"<option>Protected</option>\n" +
						"</select></td></tr>\n" +
						"</table>\n" +
						"<input type='hidden' name='editListName' value=" + editList + " /><br />\n" +
						"<input style=\"\" type=\"submit\" value=\"Send\" />\n" +
						"</form>\n" +
						"</div>\n");
			}
			
			// Edit List
			if (editListName != null) {
				System.out.println("Editing List: " + editListName);
				try {
					//String[] fields = {"isPrivate", "description"};
					int lid = Integer.parseInt(editListName);
					String[] fields = new String[2];
					String listprivacy = "\0";
					if (editListPrivacy != null && editListPrivacy.equals("Public"))
						listprivacy = "N";
					if (editListPrivacy != null && editListPrivacy.equals("Protected"))
						listprivacy = "Y";
					fields[0] = listprivacy;
					fields[1] = editListDesc;
					jdbc.updateInfoList(conn, lid, fields);
					out.println("<P>Successfully Edited List!</P>");
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Updating List Info Failed!</P>");
				}
			}
			
			// Add User to List page
			if (addListUser != null) {
				System.out.println("adding to list: " + addListUser);
				out.println("<P>Add a user to this list!</P>");
				out.println("<form action='twitter' method='post'>");
				out.println("Username: <input type='text' name='addListUserName' /><br />");
				out.println("<input type='hidden' name='addListUserLName' value=" + addListUser + " /><br />");
				out.println("<input type='submit' value='Add User' />");
				out.println("</form>");
			}
			
			// Add User to List
			if (addListUserName != null) {
				System.out.println("User adding to list: " + addListUserName + " to List: " + addListUserLName);
				try {
					int lid = Integer.parseInt(addListUserLName);
					jdbc.addMemberToList(conn, user, addListUserName, lid);
					out.println("<P>Successfully Added User: " + addListUserName + "!</P>");
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Adding User to List Failed!</P>");
				}
			}
			
			// Follow List
			if (addListFollow != null) {
				System.out.println("List to Follow: " + addListFollow);
				try {
					int lid = Integer.parseInt(addListFollow);
					jdbc.followList(conn, user, lid);
					out.println("<P>Successfully Followed List!</P>");
					doGet(request, response);
					return;
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Following List Failed!</P>");
				}
			}
			
			// UnFollow List
			if (remListFollow != null) {
				System.out.println("List to Follow: " + remListFollow);
				try {
					int lid = Integer.parseInt(remListFollow);
					jdbc.unfollowList(conn, user, lid);
					out.println("<P>Successfully UnFollowed List!</P>");
					doGet(request, response);
					return;
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Following List Failed!</P>");
				}
			}
			
			// Delete User From List
			if (delListUser != null) {
				int lid = Integer.parseInt(delListUserL);
				System.out.println("Deleting user: " + delListUser + " From list: " + delListUserL);
				try {
					jdbc.remMemberFromList(conn, delListUser, lid);
					out.println("<P>Successfully Deleted user " + delListUser + "!</P>");
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Deleting user from list failed!</P>");
				}
			}
			
			// Allow user to follow
			if (allowListUser != null) {
				int lid = Integer.parseInt(allowListUserL);
				System.out.println("Allowing user: " + allowListUser + " From list: " + lid);
				try {
					jdbc.followListAccepted(conn, allowListUser, lid);
					out.println("<P>Successfully Allowed user " + allowListUser + "!</P>");
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Allowing user to follow list!</P>");
				}
			}
			
			// Allow member to join list
			if (allowListMember != null) {
				int lid = Integer.parseInt(allowListMemberL);
				System.out.println("Allowing member: " + allowListMember + " From list: " + lid);
				try {
					jdbc.addMemberToListAccepted(conn, allowListMember, lid);
					out.println("<P>Successfully Allowed member " + allowListMember + "!</P>");
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Allowing member to list!</P>");
				}
			}
			
			// Login
			if (luser != null && lpass != null) {
				ResultSet theUser = null;
				try {
					theUser = jdbc.getUser(conn, luser);
				}
				catch (SQLException e) {
					theUser = null;
				}
				if (theUser == null) {
					out.println("<P>Uh Oh, No user by that name exists!</P>");
				}
				else {
					String correct_pass = theUser.getString("pass");
					if (correct_pass.equals(lpass)) {
						out.println("<P>Welcome back " + luser + "!</P>");
						session.setAttribute("Username", luser);
						doGet(request, response);
						return;
					} else {
						out.println("<P>The user/pass combo was incorrect</P>");
					}
				}
			}
			
			// Show Hashtags
			if (hashtag != null) {
				out.println("<P>Here's a List of all Tweets that have tag " + hashtag + " !</P>");
				out.println("<div id=\"listTweets\" >\n");
				try {
					LinkedList<LinkedList<String>> getAllTweets = jdbc.getHashtags(conn, user, hashtag);
					LinkedList<String> authors = getAllTweets.get(0);
					LinkedList<String> tweets = getAllTweets.get(1);
					LinkedList<String> dates = getAllTweets.get(2);
					LinkedList<String> msgIds = getAllTweets.get(3);
					for (int i = 0; i < authors.size(); i++) {
						String favString = "twitter?fav=" + msgIds.get(i);
						String retweetString = "twitter?retweet=" + msgIds.get(i);
						String deltweetString = "twitter?deltweet=" + msgIds.get(i);
						out.println("<div class='tweet'>\n");
						out.println("<span class='author'>" + authors.get(i) + "</span>\n");
						out.println("<span class='name'>" + dates.get(i) + "</span><br />\n");
						out.println("<span class='text'>");
						
						String tweetContent = tweets.get(i);
						char[] thetweet = tweetContent.toCharArray();
						for (int l = 0; l < thetweet.length; l++) {
							char cur = thetweet[l];
							if (cur == '@') {
								StringBuffer themen = new StringBuffer();
								for (int g = l+1; g < thetweet.length; g++) {
									char cur2 = thetweet[g];
									if (cur2 == ' ') {
										out.print("<a href=\"twitter?mentions=" + themen.toString() + "\">@" + 
												themen.toString() + "</a>");
										l = g - 1;
										break;
									}
									themen.append(cur2);
								}
							}
							else if (cur == '#') {
								StringBuffer thetag = new StringBuffer();
								for (int g = l+1; g < thetweet.length; g++) {
									char cur2 = thetweet[g];
									if (cur2 == ' ') {
										out.print("<a href=\"twitter?hashtag=" + thetag.toString() + "\">#" + 
												thetag.toString() + "</a>");
										l = g - 1;
										break;
									}
									thetag.append(cur2);
								}
							}
							else
								out.print(cur);
						}
						
						out.println("</span>\n");
						out.println("<div class='options'>\n");
						out.println("<a href="+ favString +" class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/favorite.png\" />favorite</a>\n");
						out.println("<a href=" + retweetString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>retweet</a>\n");
						out.println("<a href=\"#\" class=\"link linkReplyBox\"><img class=\"optionsIcon\" src=\""+images+"/reply.png\" />reply</a>\n");
						if (user.equals(authors.get(i)))
							out.println("<a href=" + deltweetString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>DELETE</a>\n");
						out.println("</div>\n");
						out.println("</div>\n");
					}	
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting Tweets Failed!</P>");
				}
				out.println("</div>\n");
			}
			
			// Show Mentions
			if (mentions != null) {
				out.println("<P>Here's a List of all Tweets that Mention " + mentions + " !</P>");
				out.println("<div id=\"listTweets\" >\n");
				try {
					LinkedList<LinkedList<String>> getAllTweets = jdbc.getMentions(conn, user, mentions);
					LinkedList<String> authors = getAllTweets.get(0);
					LinkedList<String> tweets = getAllTweets.get(1);
					LinkedList<String> dates = getAllTweets.get(2);
					LinkedList<String> msgIds = getAllTweets.get(3);
					for (int i = 0; i < authors.size(); i++) {
						String favString = "twitter?fav=" + msgIds.get(i);
						String retweetString = "twitter?retweet=" + msgIds.get(i);
						String deltweetString = "twitter?deltweet=" + msgIds.get(i);
						out.println("<div class='tweet'>\n");
						out.println("<span class='author'>" + authors.get(i) + "</span>\n");
						out.println("<span class='name'>" + dates.get(i) + "</span><br />\n");
						out.println("<span class='text'>");
						
						String tweetContent = tweets.get(i);
						char[] thetweet = tweetContent.toCharArray();
						for (int l = 0; l < thetweet.length; l++) {
							char cur = thetweet[l];
							if (cur == '@') {
								StringBuffer themen = new StringBuffer();
								for (int g = l+1; g < thetweet.length; g++) {
									char cur2 = thetweet[g];
									if (cur2 == ' ') {
										out.print("<a href=\"twitter?mentions=" + themen.toString() + "\">@" + 
												themen.toString() + "</a>");
										l = g - 1;
										break;
									}
									themen.append(cur2);
								}
							}
							else if (cur == '#') {
								StringBuffer thetag = new StringBuffer();
								for (int g = l+1; g < thetweet.length; g++) {
									char cur2 = thetweet[g];
									if (cur2 == ' ') {
										out.print("<a href=\"twitter?hashtag=" + thetag.toString() + "\">#" + 
												thetag.toString() + "</a>");
										l = g - 1;
										break;
									}
									thetag.append(cur2);
								}
							}
							else
								out.print(cur);
						}
						
						out.println("</span>\n");
						out.println("<div class='options'>\n");
						out.println("<a href="+ favString +" class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/favorite.png\" />favorite</a>\n");
						out.println("<a href=" + retweetString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>retweet</a>\n");
						out.println("<a href=\"#\" class=\"link linkReplyBox\"><img class=\"optionsIcon\" src=\""+images+"/reply.png\" />reply</a>\n");
						if (user.equals(authors.get(i)))
							out.println("<a href=" + deltweetString + " class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/retweet.png\" style=\"height: 15px;\"/>DELETE</a>\n");
						out.println("</div>\n");
						out.println("</div>\n");
					}	
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting Tweets Failed!</P>");
				}
				out.println("</div>\n");
			}
			
			// Show Favorites
			if (showFavorites != null) {
				out.println("<P>Here's a List of Your Favorite Tweets!</P>");
				out.println("<div id=\"listTweets\" >\n");
				try {
					LinkedList<LinkedList<String>> getFavs = jdbc.getMyFavorites(conn, user);
					LinkedList<String> authors = getFavs.get(0);
					LinkedList<String> tweets = getFavs.get(1);
					LinkedList<String> dates = getFavs.get(2);
					LinkedList<String> msgIds = getFavs.get(3);
					for (int i = 0; i < authors.size(); i++) {
						String delString = "twitter?rfav=" + msgIds.get(i);
						out.println("<div class='tweet'>\n");
						out.println("<span class='author'>" + authors.get(i) + "</span>\n");
						out.println("<span class='name'>" + dates.get(i) + "</span><br />\n");
						out.println("<span class='text'>" + tweets.get(i) + "</span>\n");
						out.println("<div class='options'><a href="+ delString +" class=\"link\"><img class=\"optionsIcon\" src=\""+images+"/favorite.png\" />Remove Favorite</div>\n");
						out.println("</div>\n");
					}	
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting Favorites Failed!</P>");
				}
				out.println("</div>\n");
			}
			
			// Update Existing Account
			if (user != null && pseudo == null && password != null) {
				if (bio == null)
					bio = "";
				if (location == null)
					location = "";
				if (webpage == null)
					webpage = "";
				String[] args = new String[9];
				args[0] = password;
				args[1] = privacy;
				args[2] = firstName;
				args[3] = lastName;
				args[4] = language;
				args[5] = timezone;
				args[6] = bio;
				args[7] = location;
				args[8] = webpage;
				jdbc.updateUser(conn, user, args);
				out.println("<P>Update Account Info Successful!</P>");
			}
			
			// Create new Account
			if (pseudo != null) {
				ResultSet theUser = null;
				try {
					theUser = jdbc.getUser(conn, pseudo);
				}
				catch (SQLException e) {
					theUser = null;
				}
				String userEmail = null;
				try {
					userEmail= jdbc.getUserEmail(conn, email);
				}
				catch (SQLException e) {
					userEmail = null;
				}
				if (theUser != null || userEmail != null) {
					if (theUser != null)
						out.println("<P>The username: " +pseudo+ " is taken!</P>");
					if (userEmail != null)
						out.println("<P>The email: " +email+ " is already being used!</P>");
				}
				else {
					if (bio == null)
						bio = "";
					if (location == null)
						location = "";
					if (webpage == null)
						webpage = "";
					String[] args = new String[11];
					args[0] = pseudo;
					args[1] = password;
					args[2] = privacy;
					args[3] = firstName;
					args[4] = lastName;
					args[5] = email;
					args[6] = language;
					args[7] = timezone;
					args[8] = bio;
					args[9] = location;
					args[10] = webpage;
					jdbc.newUser(conn, args);
					out.println("<P>Thanks for joining the site " +firstName+ "!</P>");
				    session.setAttribute("Username", pseudo);
				}
			}
			
			// Create New List
			if (listName != null) {
				char listprivacy = '\0';
				if (listPrivacy != null && listPrivacy.equals("Public"))
					listprivacy = 'N';
				if (listPrivacy != null && listPrivacy.equals("Protected"))
					listprivacy = 'Y';
				if (listName == null)
					listName = " ";
				if (listDesc == null)
					listDesc = " ";
				if (listUsers == null)
					listUsers = " ";
				try {
					jdbc.newList(conn, user, listprivacy, listName, listDesc);
					out.println("<P>Creating List " + listName + " Successful!</P>");
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Creating New List Failed!</P>");
				}
				String[] listusers = listUsers.split(" ");
				for (int i = 0; i < listusers.length; i++) {
					ResultSet theUser = null;
					try {
						theUser = jdbc.getUser(conn, listusers[i]);
					}
					catch (SQLException e) {
						theUser = null;
					}
					if (theUser != null) {
						try {
							jdbc.addMemberToList(conn, user, listusers[i], listName);
							out.println("<P>Adding User " + listusers[i] + " Successful!</P>");
						}
						catch (SQLException e) {
							e.printStackTrace();
							out.println("<P>Error, Adding Member To List!</P>");
						}
					}
					else {
						out.println("<P>User " + listusers[i] + " Does Not Exist!</P>");
					}
				}
			}
			
			// New List Register Page
			if (nlist != null) {
				out.println("<P>Create a New List!</P>");
				out.println("<P>Add Users By Space Separating Their Usernames</P>");
				out.println("<div id=\"listBox\" >\n" +  
						"<form method=\"post\" action=\"twitter\">\n" +
						"<table>\n" +
						"<tr><td style=\"width:90px;text-align:right;\">Name :</td><td><input class=\"nameList\" style=\"width:300px;\" name='listName' /></td></tr>\n" +
						"<tr><td style=\"width:90px;text-align:right;\">Description :</td><td><textarea maxlength=\"142\" class=\"tweetAreaUnFocus descriptionList\" name='listDesc' rows=\"3\" style=\"width:300px;position:center;\" ></textarea></td></tr>\n" +
						"<tr><td style=\"width:90px;text-align:right;\">Privacy :</td><td>\n" +
						"<select style=\"width:300px;\" name=\"listPrivacy\" id=\"privacy-value\">\n" +
						"<option selected=\"selected\">Public</option>\n" +
						"<option>Protected</option>\n" +
						"</select></td></tr>\n" +
						"<tr><td style=\"width:90px;text-align:right;\">AddUsers :</td><td><input class=\"nameList\" style=\"width:300px;\" name=\"listUsers\"/></td></tr>\n" +
						"</table>\n" +
						"<input style=\"\" type=\"submit\" value=\"Send\" />\n" +
						"</form>\n" +
						"</div>\n");
			}
			
			// Show List
			if (showList != null) {
				
				try {
					LinkedList<LinkedList<String>> listinfo = jdbc.getListInfo(conn, showList);
					
					// lists, desc, privacy, members, waitingmems <--- jdbc.getLists()
					String theListName = listinfo.get(0).get(0);
					String lDesc = listinfo.get(1).get(0);
					String lPriv = listinfo.get(2).get(0);
					if (lPriv.equals("Y"))
						lPriv = "Protected";
					else
						lPriv = "Public";
					String lAuthor = listinfo.get(3).get(0);
					LinkedList<String> lmems = listinfo.get(4);
					LinkedList<String> lwmems = listinfo.get(5);
					String lid = listinfo.get(6).get(0);
					LinkedList<String> lwfmems = listinfo.get(7);
					LinkedList<String> lf = listinfo.get(8);
					
					out.println("<div class=\"followers\">List: " + theListName + " Creator: " + lAuthor + 
							" Privacy: " + lPriv + "</div>\n");
					out.println("<P>Description: " + lDesc +"</P>\n");
					
					out.println("<div class=\"followers\">List Members:</div>\n");
					for (int j = 0; j < lmems.size(); j++) {
						out.println("<table>\n");
						out.println("<tr>\n");
						out.println("<td><label>" + lmems.get(j) + "</label></td>\n");
						if (user.equals(lAuthor)) {
							out.println("<td>\n");
							out.println("<form action='twitter' method='post'>");
							out.println("<input type='hidden' name='delListUser' value=" + lmems.get(j) + " /><br />");
							out.println("<input type='hidden' name='delListUserL' value=" + lid + " /><br />");
							out.println("<input type='submit' value='Remove User' />");
							out.println("</form>\n");
							out.println("</td>\n");
						}
						out.println("</tr>\n");
						out.println("</table>\n");
					}
					if (user.equals(lAuthor) && lPriv.equals("Protected")) {
						out.println("<div class=\"followers\">Members Waiting for Admission:</div>\n");
						for (int j = 0; j < lwmems.size(); j++) {
							out.println("<table>\n");
							out.println("<tr>\n");
							out.println("<td><label>" + lwmems.get(j) + "</label></td>\n");
							out.println("<td>\n");
							out.println("<form action='twitter' method='post'>");
							out.println("<input type='hidden' name='allowListMember' value=" + lwmems.get(j) + " /><br />");
							out.println("<input type='hidden' name='allowListMemberL' value=" + lid + " /><br />");
							out.println("<input type='submit' value='Allow Member' />");
							out.println("</form>\n");
							out.println("</td>\n");
							out.println("</tr>\n");
							out.println("</table>\n");
						}
						out.println("<div class=\"followers\">Followers:</div>\n");
						for (int j = 0; j < lf.size(); j++) {
							out.println("<table>\n");
							out.println("<tr>\n");
							out.println("<td><label>" + lf.get(j) + "</label></td>\n");
							out.println("</tr>\n");
							out.println("</table>\n");
						}
						out.println("<div class=\"followers\">People Waiting to Follow:</div>\n");
						for (int j = 0; j < lwfmems.size(); j++) {
							out.println("<table>\n");
							out.println("<tr>\n");
							out.println("<td><label>" + lwfmems.get(j) + "</label></td>\n");
							out.println("<td>\n");
							out.println("<form action='twitter' method='post'>");
							out.println("<input type='hidden' name='allowListUser' value=" + lwfmems.get(j) + " /><br />");
							out.println("<input type='hidden' name='allowListUserL' value=" + lid + " /><br />");
							out.println("<input type='submit' value='Allow User' />");
							out.println("</form>\n");
							out.println("</td>\n");
							out.println("</tr>\n");
							out.println("</table>\n");
						}
					}
					
					out.println("<div class=\"followers\">Other Options:</div>\n");
					
					out.println("<form action='twitter' method='post'>");
					out.println("<input type='hidden' name='addListFollow' value=" + lid +" /><br />");
					out.println("<input type='submit' value='Follow This List' />");
					out.println("</form>");
					
					out.println("<form action='twitter' method='post'>");
					out.println("<input type='hidden' name='remListFollow' value=" + lid +" /><br />");
					out.println("<input type='submit' value='UnFollow This List' />");
					out.println("</form>");
					
					if (user.equals(lAuthor)) {
					
						out.println("<form action='twitter' method='post'>");
						out.println("<input type='hidden' name='editList' value=" + lid +" /><br />");
						out.println("<input type='submit' value='Edit This List' />");
						out.println("</form>");
						
						out.println("<form action='twitter' method='post'>");
						out.println("<input type='hidden' name='addListUser' value=" + lid +" /><br />");
						out.println("<input type='submit' value='Add User' />");
						out.println("</form>");
						
						out.println("<form action='twitter' method='post'>");
						out.println("<input type='hidden' name='delList' value=" + lid +" /><br />");
						out.println("<input type='submit' value='DELETE THIS LIST' />");
						out.println("</form>");
					
					}
					
				}
				catch (SQLException e) {
					e.printStackTrace();
					out.println("<P>Error, Getting List Info!</P>");
				}
				
			}
			
			// New Account Register Page
			if (nuser != null) {
				out.println("<div id=\"register\" class=\"content\">\n" +
						"<h3>Register</h3>\n" +
						"<form id=\"form-register\" action='twitter' method='post'>\n" +
						"<table class=\"table-register\">\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\"><label for=\"pseudo\">* Username:</label></td>\n" +
						"<td class=\"value-input-register\"><input type=\"text\" class=\"inputUnFocus\" name=\"pseudo\" value=\"\" id=\"name-value\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-name-value\">The pseudo is not valid.</td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">* Password:</td>\n" +
						"<td class=\"value-input-register\"><input type=\"password\" class=\"inputUnFocus\" name=\"password\" value=\"\" title=\"password\" id=\"password-value\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-password-value\">A password is required.</td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\"><label for=\"repassword\">* Re-type Password:</label></td>\n" +
						"<td class=\"value-input-register\"><input type=\"password\" class=\"inputUnFocus\" name=\"repassword\" value=\"\" title=\"password\" id=\"repassword-value\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-repassword-value\">The passwords don't match.</td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">* First name:</td>\n" +
						"<td class=\"value-input-register\"><input type=\"text\" class=\"inputUnFocus\" name=\"firstName\" value=\"\" title=\"firstName\" id=\"firstName-value\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-firstName-value\">Your first name is required.</td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">* Last name:</td>\n" +
						"<td class=\"value-input-register\"><input type=\"text\" class=\"inputUnFocus\" name=\"lastName\" value=\"\" title=\"lastName\" id=\"lastName-value\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-lastName-value\">Your last name is required.</td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">* E-mail:</td>\n" +
						"<td class=\"value-input-register\"><input type=\"text\" class=\"inputUnFocus\" name=\"email\" value=\"\" id=\"email-value\"  title=\"email\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-email-value\">The email address is not valid.</td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">Privacy level:</td>\n" +
						"<td class=\"value-input-register\">\n" +
						"<select name=\"privacy\" id=\"privacy-value\">\n" +
						"<option selected=\"selected\">Public</option>\n" +
						"<option>Protected</option>\n" +
						"</select>\n" +
						"</td>\n" +
						"<td class=\"js-input-register\" id=\"js-privacy-value\"></td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">Bio:</td>\n" +
						"<td class=\"value-input-register\"><textarea class=\"tweetAreaUnFocus\" name=\"bio\" value=\"\" title=\"bio\" id=\"bio-value\" cols=\"100\" maxlength=\"142\" size=\"142\"></textarea></td>\n" +
						"<td class=\"js-input-register\" id=\"js-bio-value\">142</td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">Webpage:</td>\n" +
						"<td class=\"value-input-register\"><input type=\"text\" class=\"inputUnFocus\" name=\"webpage\" value=\"\" id=\"webpage-value\" title=\"webpage\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-webpage-value\"></td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">Location:</td>\n" +
						"<td class=\"value-input-register\"><input type=\"text\" class=\"inputUnFocus\" name=\"location\" value=\"\" id=\"location-value\" title=\"location\" /></td>\n" +
						"<td class=\"js-input-register\" id=\"js-location-value\"></td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">Timezone:</td>\n" +
						"<td class=\"value-input-register\">\n" +
						"<select name=\"timezone\" id=\"timezone-value\">\n" +
						"<option selected=\"selected\">None</option>\n" +
						"<option>UTC-12</option>\n" +
						"<option>UTC-11</option>\n" +
						"<option>UTC-10</option>\n" +
						"<option>UTC-09</option>\n" +
						"<option>UTC-08</option>\n" +
						"<option>UTC-07</option>\n" +
						"<option>UTC-06</option>\n" +
						"<option>UTC-05</option>\n" +
						"<option>UTC-04</option>\n" +
						"<option>UTC-03</option>\n" +
						"<option>UTC-02</option>\n" +
						"<option>UTC-01</option>\n" +
						"<option>UTC</option>\n" +
						"<option>UTC+01</option>\n" +
						"<option>UTC+02</option>\n" +
						"<option>UTC+03</option>\n" +
						"<option>UTC+04</option>\n" +
						"<option>UTC+05</option>\n" +
						"<option>UTC+06</option>\n" +
						"<option>UTC+07</option>\n" +
						"<option>UTC+08</option>\n" +
						"<option>UTC+09</option>\n" +
						"<option>UTC+10</option>\n" +
						"<option>UTC+11</option>\n" +
						"<option>UTC+12</option>\n" +
						"<option>UTC+13</option>\n" +
						"<option>UTC+14</option>\n" +
						"</select>\n" +
						"</td>\n" +
						"<td class=\"js-input-register\" id=\"js-timezone-value\"></td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td class=\"label-input-register\">Language:</td>\n" +
						"<td class=\"value-input-register\">\n" +
						"<select id=\"language-value\" name=\"language\">\n" +
						"<option selected=\"selected\">English</option>\n" +
						"<option>French</option>\n" +
						"<option>German</option>\n" +
						"<option>Spanish</option>\n" +
						"</select>\n" +
						"</td>\n" +
						"<td class=\"js-input-register\" id=\"js-language-value\"></td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td id=\"required_text\" class=\"label-input-register\">* Required</td>\n" +
						"<td class=\"value-input-register\" />\n" +
						"<td class=\"js-input-register\" id=\"js-required-value\"></td>\n" +
						"</tr>\n" +
						"<tr>\n" +
						"<td colspan=\"2\" id=\"buttons-register\">\n" +
						"<input type=\"submit\" />\n" +
						"<input type=\"reset\" />\n" +
						"</td>\n" +
						"<td/>\n" +
						"</tr>\n" +
						"</table>\n" +
						"</form>\n" +
						"</div>\n"); 
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		finally {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		out.println("</div></html>\n");
		
	}
	
}